<template>
<el-card style="max-width: 480px; margin: 0 auto;">
    <template #header>
      <div class="card-header">
        <span v-if='editType==1'>修改密码</span>
        <span v-else-if='editType==2'>新增普通用户</span>
        <span v-else-if='editType==3'>新增交通管理员</span>
        <el-icon class="close-btn" @click="$emit('close')"><Close /></el-icon>
      </div>
    </template>
    <el-form
      :model="form"
      class="login-form"
      label-width="60px"
      label-position="right"
      size="large"
    >
      <el-form-item label="用户名">
        <el-input v-model="form.username" :prefix-icon="User" />
      </el-form-item>
      <el-form-item label="新密码">
        <el-input
          type="password"
          v-model="form.newPassword"
          show-password
          :prefix-icon="Lock"
        />
      </el-form-item>
      <el-form-item>
        <div class="btn">
          <el-button type="primary" @click="handleSubmit">提交</el-button>
        </div>
      </el-form-item>
    </el-form>
    
  </el-card>

</template>
<script setup>
import { ref,defineProps,defineEmits } from "vue";
import { User, Lock,Close} from "@element-plus/icons-vue";

import { userUpdateInfoHttp,userRegisterHttp} from "@/api/user";
const props = defineProps({
    form:{
        type:Object,
        default:()=>({
            username:"",
            newPassword:"",
            type:''
        })
    },
    editType:{

    }
})
const emits = defineEmits(['submit','close'])

const handleSubmit = async () => {
    if(props.editType==1){
        const res = await userUpdateInfoHttp({
        username:props.form.username,
        newPassword:props.form.newPassword,
        type:props.form.type
    });
    
    }else{
        const res = await userRegisterHttp({
        username:props.form.username,
        password:props.form.newPassword,
        type:props.form.type
        });
    }
    emits('submit')

}
</script>
<style scoped>
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    cursor: pointer;
}
</style>